<?php
require_once 'init.php';



/* ---- User Functions ------------------------------------------------------ */
// ABMC

function login($user,$password){
    $db = getDatabase();
    
    
    $bind['email']=$user;
    $bind['password']=$password;
    
    $where[]='email = :email';
    $where[]='password = :password';

    return $db->select('users',$where,$bind);
}

function registerUser($data){
    $db = getDatabase();

    $data["session_id"]=session_id();
	$data["facebook"]='';       
	$data["ip"]=$_SERVER['REMOTE_ADDR'];   
	$data["user_info"]= $_SERVER['HTTP_USER_AGENT'];   

    $db->insert('users',$data);
}

/* ---- track Functions ------------------------------------------------------ */

function create_track($data){
    $db = getDatabase();

    $data["session_id"]=session_id();
 
	$data["ip"]=$_SERVER['REMOTE_ADDR'];   
	$data["user_info"]= $_SERVER['HTTP_USER_AGENT'];   

    return $db->insert('tracks',$data);
}
function read_track(){}
function update_track(){}
function delete_track(){}

function user_list_tracks(){
    $db = getDatabase();
    
    
    $bind['user_id']=$_SESSION['user_id'];
    $bind['dt']=date('Y-m-d 00:00:00');

    
    $where[]='user_id = :user_id';
    $where[]='dt >= :dt';
//     $where[]='password = :password';

    return $db->select('tracks',$where,$bind,'*',' id asc',100,0);

}